home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir28 / papc20.zip / ROOT.PRG < prev    next >
Text File  |  1994-03-25  |  632b  |  31 lines

  1. ; calculate root of x^3 - (6 * x^2) + (11 * x) - 1 = 0 using Newton's method
  2. ; correct answer is 0.0958
  3. LBL findroot
  4. 10 fix
  5. E-10 0 sto         ; tolerance
  6. 0.9                ; initial guess
  7. 100.00001 1 sto    ; loop counter for max iterations
  8. LBL loop
  9. DUP DUP XEQ f OVER XEQ fprime / -  ; calculate x'
  10. DUP ROT -
  11. ABS
  12. 0 RCL <=
  13. GTO OK
  14. DROP
  15. 1 DSE
  16. GTO loop
  17. PUTS "No convergence after 100 iterations\n"
  18. QUIT
  19. LBL OK
  20. DROP
  21. PUTS "Answer = " 0 PUTX PUTS "\n\n"
  22. QUIT
  23.  
  24. LBL f   ; x^3 - (6 * x^2) + (11 * x) - 1
  25. DUP 3^ OVER 2^ 6* - SWAP 11* + 1-
  26. RTN
  27.  
  28. LBL fprime   ; (3*x^2) - (12*x) + 11
  29. DUP 2^ 3* SWAP 12* - 11+
  30. END
  31.